package com.yyq.gxdc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyq.gxdc.entity.Coupon;
import com.yyq.gxdc.mapper.CouponMapper;
import com.yyq.gxdc.service.ICouponService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements ICouponService {
    @Resource
    private CouponMapper couponMapper;

    @Override
    public PageInfo<Coupon> findPage(Coupon conditioin, int pageNum, int pageSize) {
        return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> {
            couponMapper.find(conditioin);
        });
    }
    @Override
    public int add(Coupon coupon) {
        return couponMapper.insert(coupon);
    }
    @Override
    public Coupon findById(Integer id) {
        return couponMapper.findById(id);
    }

    @Override
    public Coupon getDetailByRid(Integer rid){
        Coupon coupon = couponMapper.findById(rid);

        return coupon;
    };

    @Override
    public int update(Coupon dish) {
        return couponMapper.updateById(dish);
    }
    @Override
    public int delete(Integer id) {
        return couponMapper.deleteById(id);
    }

    @Override
    public IPage<Coupon> getAllCoupon(Page<Coupon> page, Coupon conditioin){
        return couponMapper.getAllCoupon(page,conditioin);
    };
}

